<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>江西农业大学图书馆 - 用户注册</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
    <style>
        @font-face {
            font-family: 'XingKai';
            src: url('https://cdn.jsdelivr.net/gh/googlefonts/noto-cjk@main/Sans/OTF/Chinese/NotoSansCJKsc-Bold.otf');
        }
        .system-title {
            font-family: 'XingKai', cursive;
            font-size: 28px;
            font-weight: bold;
            text-align: center;
            margin: 20px 0;
        }
    </style>
</head>
<body>
    <div class="container mt-5">
        <h1 class="system-title">江西农业大学图书馆</h1>
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header">
                        <h3 class="text-center">用户注册</h3>
                    </div>
                    <div class="card-body">
                        <form id="registerForm">
                            <div class="mb-3">
                                <label class="form-label">用户名</label>
                                <input type="text" class="form-control" id="username" required>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">密码</label>
                                <input type="password" class="form-control" id="password" required>
                            </div>
                            <button type="submit" class="btn btn-primary w-100">注册</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const user = {
                username: document.getElementById('username').value,
                password: document.getElementById('password').value,
                role: 0 // 默认角色为普通用户
            };
            
            fetch('/api/users/register', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(user)
            })
            .then(response => response.json())
            .then(result => {
                if (result) {
                    alert('注册成功');
                    window.location.href = 'login.html'; // 注册成功后跳转到登录页面
                } else {
                    alert('注册失败');
                }
            });
        });
    </script>
</body>
</html> 